package com.example.b_308.myapplication.view.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.view.base.BaseFragment;
import com.example.b_308.myapplication.view.main.Base.IMessageView;
import com.example.b_308.myapplication.view.main.Base.MessageAdapter;
import com.example.b_308.myapplication.model.been.MessageBeen;
import com.example.b_308.myapplication.controller.MessageController;

import java.util.List;

/**
 * Created by B-308 on 2017/11/17.
 */
public class MessageFragment extends BaseFragment implements IMessageView {
    ListView lv_message;
    List<MessageBeen> messageBeens;
    MessageAdapter messageAdater;
    MessageController messageController;



    @Nullable
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.fragment_message,null);
        lv_message = (ListView) view.findViewById(R.id.lv_message);
        messageController = new MessageController(this);
        messageController.getList();
        return view;
    }

    @Override
    protected void init() {

    }

    @Override
    protected View setContentView(LayoutInflater inflater) {
        return null;
    }

    @Override
    public void onRequestListSuccess(List<MessageBeen> messageBeens) {
        if(null != messageAdater){
            messageAdater.notifyChango(messageBeens);
        }else {
            messageAdater = new MessageAdapter(messageBeens,getActivity());
        }
        getActivity().runOnUiThread(new Runnable(){
            public void run(){
                lv_message.setAdapter(messageAdater);
            }
        });

    }

    @Override
    public void fail(String message) {

    }
}
